package com.lzh.chatnote.user.dao;

import com.lzh.chatnote.user.domain.entity.RolePermission;
import com.lzh.chatnote.user.mapper.RolePermissionMapper;
import com.lzh.chatnote.user.service.RolePermissionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * <p>
 * 角色权限关系表 服务实现类
 * </p>
 *
 * @author lzh
 * @since 2025-10-09
 */
@Service
public class RolePermissionDao extends ServiceImpl<RolePermissionMapper, RolePermission> implements RolePermissionService {

    public List<Long> queryUserPermissionListIds(List<Long> roles) {
        return Optional.ofNullable(lambdaQuery()
                .in(RolePermission::getRoleId, roles)
                .list()).orElse(Collections.emptyList()).stream().map(RolePermission::getPermissionId).collect(Collectors.toList());
    }
}
